﻿// This is here as an example of a way to create a data contract using Soap
using System;
using System.Runtime.Serialization;

namespace SilverCrmSoap.CrmSdk
{
    [DataContract(Name="Annotation",IsReference=true)]
    public class Annotation : UserOwnedEntity
    {
        public Annotation()
        {
            if (Attributes == null) Attributes = new AttributeCollection();
            if (LogicalName == null) LogicalName = "annotation";
        }

        public const int EntityTypeCode = 5;

        [DataMember]
        public string Subject
        {
            get
            {
                return GetAttributeValue<string>("subject");
            }
            set
            {
                SetAttributeValue("Subject", value);
            }
        }

        [DataMember]
        public string FileName
        {
            get
            {
                return GetAttributeValue<string>("filename");
            }
            set
            {
                SetAttributeValue("FileName", value);
            }
        }

        [DataMember]
        public EntityReference ObjectId
        {
            get
            {
                return GetAttributeValue<EntityReference>("objectid");
            }
            set
            {
                SetAttributeValue("ObjectId", value);
            }
        }

        [DataMember]
        public string NoteText {
            get
            {
                return GetAttributeValue<string>("notetext");
            }
            set
            {
                SetAttributeValue("NoteText", value);
            }
        }

        [DataMember]
        public string MimeType {
            get
            {
                return GetAttributeValue<string>("mimetype");
            }
            set
            {
                SetAttributeValue("MimeType", value);
            }
        }

        [DataMember]
        public string DocumentBody { 
            get
            {
                return GetAttributeValue<string>("documentbody");
            }
            set
            {
                SetAttributeValue("DocumentBody", value);
            }
        }

        [DataMember]
        public byte[] Attachment
        {
            get
            {
                return Convert.FromBase64String(DocumentBody);
            }
            set
            {
                DocumentBody = Convert.ToBase64String(value);
            }
        }

        [DataMember]
        public Nullable<bool> IsDocument
        {
            get
            {
                return GetAttributeValue<Nullable<bool>>("isdocument");
            }
            set
            {
                SetAttributeValue("IsDocument", value);
            }
        }
    }
}
